/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.sanerzone.smscenter.modules.sms.web;

import com.sanerzone.jeebase.common.config.Global;
import com.sanerzone.jeebase.common.persistence.Page;
import com.sanerzone.jeebase.common.utils.StringUtils;
import com.sanerzone.jeebase.common.web.BaseController;
import com.sanerzone.smscenter.modules.sms.entity.SmsReceiveAccount;
import com.sanerzone.smscenter.modules.sms.service.SmsReceiveAccountService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 单表生成Controller
 * @author ThinkGem
 * @version 2018-04-25
 */
@Controller
@RequestMapping(value = "${adminPath}/sms/smsReceiveAccount")
public class SmsReceiveAccountController extends BaseController {

	@Autowired
	private SmsReceiveAccountService smsReceiveAccountService;
	
	@ModelAttribute
	public SmsReceiveAccount get(@RequestParam(required=false) String id) {
		SmsReceiveAccount entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = smsReceiveAccountService.get(id);
		}
		if (entity == null){
			entity = new SmsReceiveAccount();
		}
		return entity;
	}
	
	@RequiresPermissions("sms:smsReceiveAccount:view")
	@RequestMapping(value = {"list", ""})
	public String list(SmsReceiveAccount smsReceiveAccount, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<SmsReceiveAccount> page = smsReceiveAccountService.findPage(new Page<SmsReceiveAccount>(request, response), smsReceiveAccount);
		model.addAttribute("page", page);
		return "modules/sms/smsReceiveAccountList";
	}

	@RequiresPermissions("sms:smsReceiveAccount:view")
	@RequestMapping(value = "form")
	public String form(SmsReceiveAccount smsReceiveAccount, Model model) {
		model.addAttribute("smsReceiveAccount", smsReceiveAccount);
		return "modules/sms/smsReceiveAccountForm";
	}

	@RequiresPermissions("sms:smsReceiveAccount:edit")
	@RequestMapping(value = "save")
	public String save(SmsReceiveAccount smsReceiveAccount, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, smsReceiveAccount)){
			return form(smsReceiveAccount, model);
		}
		smsReceiveAccountService.save(smsReceiveAccount);
		addMessage(redirectAttributes, "保存单表成功");
		return "redirect:"+ Global.getAdminPath()+"/sms/smsReceiveAccount/?repage";
	}
	
	@RequiresPermissions("sms:smsReceiveAccount:edit")
	@RequestMapping(value = "delete")
	public String delete(SmsReceiveAccount smsReceiveAccount, RedirectAttributes redirectAttributes) {
		smsReceiveAccountService.delete(smsReceiveAccount);
		addMessage(redirectAttributes, "删除单表成功");
		return "redirect:"+Global.getAdminPath()+"/sms/smsReceiveAccount/?repage";
	}

}